package com.springboot.cms.broadside.controller;

import com.springboot.cms.broadside.domain.CmsCustomer;
import com.springboot.cms.broadside.service.ICmsCustomerService;
import com.springboot.common.annotation.Log;
import com.springboot.common.core.controller.BaseController;
import com.springboot.common.core.domain.AjaxResult;
import com.springboot.common.core.page.TableDataInfo;
import com.springboot.common.enums.BusinessType;
import com.springboot.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 站长信息Controller
 *
 * @author lhxz
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/cms/customer")
public class CmsCustomerController extends BaseController
{
    @Autowired
    private ICmsCustomerService cmsCustomerService;

    /**
     * 查询站长信息列表
     */
//    @PreAuthorize("@ss.hasPermi('cms:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsCustomer cmsCustomer)
    {
        startPage();
        List<CmsCustomer> list = cmsCustomerService.selectCmsCustomerList(cmsCustomer);
        return getDataTable(list);
    }

    /**
     * 导出站长信息列表
     */
    @PreAuthorize("@ss.hasPermi('cms:customer:export')")
    @Log(title = "站长信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsCustomer cmsCustomer)
    {
        List<CmsCustomer> list = cmsCustomerService.selectCmsCustomerList(cmsCustomer);
        ExcelUtil<CmsCustomer> util = new ExcelUtil<CmsCustomer>(CmsCustomer.class);
        util.exportExcel(response, list, "站长信息数据");
    }

    /**
     * 获取站长信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsCustomerService.selectCmsCustomerById(id));
    }
    /**
     * 新增站长信息
     */
    @PreAuthorize("@ss.hasPermi('cms:customer:add')")
    @Log(title = "站长信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsCustomer cmsCustomer)
    {
        return toAjax(cmsCustomerService.insertCmsCustomer(cmsCustomer));
    }

    /**
     * 修改站长信息
     */
    @PreAuthorize("@ss.hasPermi('cms:customer:edit')")
    @Log(title = "站长信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsCustomer cmsCustomer)
    {
        return toAjax(cmsCustomerService.updateCmsCustomer(cmsCustomer));
    }

    /**
     * 删除站长信息
     */
    @PreAuthorize("@ss.hasPermi('cms:customer:remove')")
    @Log(title = "站长信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsCustomerService.deleteCmsCustomerByIds(ids));
    }
}
